package autoorder.zsxmlv.action;

import autoorder.zsxmlv.po.Account;
import autoorder.zsxmlv.service.AccountService;
import common.zsxmlv.utils.PropertiesUtil;
import common.zsxmlv.vo.Result;
import common.zsxmlv.vo.Table;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @Author: ZSXM
 * @Description:
 * @Company: DingZheng
 * @Date: Create by 2018/6/2 13:50
 * @Version: 1.0
 * @Modify by:
 */
@Controller
@ResponseBody
@RequestMapping("/admin/auto_order/account")
public class AccountAction {

    @Resource
    private AccountService accountService;

    @RequestMapping("/insert")
    public Result insert(Account account) {
        return accountService.insert(account);
    }

    @RequestMapping("/getAccountById")
    public Result getAccountById(Integer id) {
        return accountService.getAccountById(id);
    }

    @RequestMapping("/deleteById")
    public Result deleteById(Integer id) {
        return accountService.deleteById(id);
    }

    @RequestMapping("/getAccountListByPage")
    public Table getAccountListByPage(Integer page,
                                      Integer limit,
                                      String username,
                                      String custname,
                                      @RequestParam(value = "disabled", required = false, defaultValue = "0") Integer disabled) {
        return accountService.getAccountListByPage(page, limit, username, custname, disabled);
    }

    @RequestMapping("/updateStatus")
    public Result updateStatus(Integer id) {
        return accountService.updateStatus(id);
    }

    @RequestMapping("/updateAccountById")
    public Result updateAccountById(Account account) {
        return accountService.updateAccountById(account);
    }

    @RequestMapping("/listByStatus")
    public List<Account> listByStatus(Integer status) {
        return accountService.listAllByStatus(status);
    }

    @RequestMapping("/batchDelete")
    public Result batchDelete(String ids) {
        return accountService.batchDeleteByIds(ids);
    }

    @RequestMapping("/uploadFile")
    public Result uploadFile(@RequestParam("file") CommonsMultipartFile file) {
        return accountService.uploadFile(file);
    }

}
